#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <glib.h>

#define MAX_NUM 10000

int main()
{
	mode_t f_attr;
	f_attr = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;

	for(int i=0; i < MAX_NUM; i++)
	{
		GString *s;
		s = g_string_new("");
		for(int j = 0; j < MAX_NUM; j++)			
		{
			g_string_append_printf(s,"%d",rand() % MAX_NUM + 1);
			g_string_append(s,"\t");
			g_string_append_printf(s,"%d",rand() % MAX_NUM + 1); 
            g_string_append(s,"\t");
			g_string_append_printf(s,"%d",rand() % MAX_NUM + 1); 
            g_string_append(s,"\t");
			g_string_append_printf(s,"%d",rand() % MAX_NUM + 1); 
            g_string_append(s,"\t");
			g_string_append_printf(s,"%d",rand() % MAX_NUM + 1); 
			g_string_append(s,"\n");
		}
		
		char *fname;
		fname = malloc(12);
		sprintf(fname,"r_glibc_%d",i);
		int f;
		f = open(fname,O_RDWR | O_CREAT,f_attr);
		write(f,s->str,s->len);
		close(f);
		free(fname);
		g_string_free(s,TRUE);
	}
}
